const animation = uni.requireNativePlugin('animation')
const dom = uni.requireNativePlugin('dom')
import unirefresh from '../tsp-load/tsp-refresh-n.vue'
import videoMenu from '../tsp-menu/tsp-menu-n.vue'
/*
 lodData 上拉加载回调
 refreshData 下拉加载回调
 */

export default {
	components: {
		unirefresh,
		videoMenu
	},
	props: {
		/* 是否开启下拉刷新 */
		loadOpen: {
			type: Boolean,
			default: true
		},
		/* 剩余多少个视频触发上拉加载 */
		surplusNum: {
			type: Number,
			default: 0 //0默认是最后一个
		},
		/* tabBar栏 0系统tabBar栏 1自定义tabBar栏 */
		tabBarShow: {
			type: Number,
			default: 0
		},
		/* 自定义tabBar的高度 */
		tabBarHeight: {
			type: Number,
			default: 50
		},
		/* 进度条离底部的距离 px*/
		speedBottom: {
			type: Number,
			default: 0
		},
		/* 初始加载完成是否自动播放 */
		autoplay: {
			type: Boolean,
			default: true
		},
		/* 是否循环播放 */
		loopPlay: {
			type: Boolean,
			default: true
		},
		/* 是否开启自动播放 */
		nextPlay: {
			type: Boolean,
			default: false
		},
		/* 是否开启双击点赞 */
		doubleOpen:{
			type: Boolean,
			default: true
		},
		/* 双击点赞屏幕是否显示桃心 */
		doubleHeart:{
			type: Boolean,
			default: true
		},
		/* 多个tab视频时需传入不同的类型 */
		swId: {
			type: String,
			default: ''
		},
		/* 是否有显示 statusBarHeight 状态栏适配 */
		showBarHeight: {
			type: Boolean,
			default: true
		},
	},
	data() {
		return {
			videoStyle: {},
			screenWidth: 0, //屏幕的宽度
			screenHeight: 0, //屏幕的高度
			vodHeight: 0, //视频部分高度
			videoNewUrl: null, //下一个视频的地址
			currentIndex: null,
			vodIndex: 0, // 当前播放视频下标
			contentShow: false,
			autoplayVideo: true, // 初始加载完成是否自动播放
			vodList: [
				/* {
					tspId:'myVideo'+ 0,
					vodUrl:"https://outin-9cc4a7aedd2a11eaabb800163e1a65b6.oss-cn-shanghai.aliyuncs.com/customerTrans/43121ec9955a1ce95146d379f15ea9bd/566eafe2-17b52f0f17b-0007-0f29-cc2-eb217.mp4",
					coverImg:'/static/image/cover1.jpg', //视频封面
					coverShow:true, //是否显示视频封面
					vodPaly:true, //是否播放、暂停视频
					object_fit:'contain', //视频的显示类型
					pauseShow:false, //是否显示暂停图标
					loadingShow:false, //是否显示loading加载动画
					fabulousShow:false,//是否点赞
					followShow:-1, //关注特效
					followReally:false, //是否关注
					sliderShow:true, //是否显示进度条
					rotateImgShow:true, //是否显示旋转头像
				} */
			],
			timeout: null, //滑动视频防抖
			bufferTime: null, //缓冲视频显示加载动画防抖
			sliderProgress: 0, //进度条滑动层宽度
			sliderTime: 0, //显示滑动进度条时变化的时间
			videoTime: 0, //视频时长 时间
			endTime: 0, //滑动进度条最终的时间
			sliderDrag: false, //是否在拖动进度
			brightSlider: false, //是否显示光亮的进度条
			sliderEndTime: null, //滑动结束隐藏光亮进度条时间延迟
			startPlayVod: false, //是否滑动结束播放下一个视频
			bufferShow: false, //显示loading加载进度的条件
			playOpen: false, //视频播放失败，是否重播视频的条件
			failTime: null, //视频播放失败，重播视频的时间
			repeatTime:null,
			preloadTime: null, //延时防抖
			shakePlay: false, //是否有遗漏的视频播放
			rotateAnti:false, //防抖旋转头像
			touchClientY: 0, //触碰的坐标
			moveClientY: 0, //移动的坐标
			moveOpacity: false, //是否透明
			speedHide:false, //滑动时隐藏进度条
			appoint:true, //初始隐藏视频和右侧头像栏
			changeVod:false, //是否正在切换视频
			muteSetup:false, //是否设置为静音
			changeIndex:0,
			changeTime:null,
			/* 双击点赞部分 */
			lastTapDiffTime: 0, //上次点击时间
			lastTapTimeoutFunc: null, //单击事件事件函数
			likeList:[], //双击点赞显示的桃心数据
			likeId:1,
			doubleOutTime:null,
			clearDoubleTime:null,
			touchInfo:{},
			/* 双击点赞显示桃心动画 */
			peachAddList:{
				list:[
					{transform:'scale(1.6)',opacity: '0.8'},
					{transform:'scale(1)',opacity: '1'},
					{transform:'scale(1.02)',opacity: '1'},
					{transform:'scale(1)',opacity: '1'}
				],
				duration:75
			},
			/* 双击点赞移除桃心动画 */
			peachRemoveList:{
				list:[
					{transform:'scale(1) translateY(0rpx)',opacity: '1'},
					{transform:'scale(1.35) translateY(-50rpx)',opacity: '0.7'},
					{transform:'scale(1.6) translateY(-100rpx)',opacity: '0'}
				],
				duration:133
			},
			pauseNum:0,
			pauseAddList:{
				list:[
					{transform:'scale(2)',opacity: '0'},
					{transform:'scale(1)',opacity: '0.35'}
				],
				duration:75
			}
		}
	},
	created() {
		const deviceInfo = uni.getSystemInfoSync();
		let topBarHeight = this.tabBarShow ? deviceInfo.statusBarHeight : 0;
		
		this.videoStyle.height = `${topBarHeight}px`;
		this.videoStyle.vodHeight = `${deviceInfo.screenWidth}px`;
		this.width = deviceInfo.screenWidth;
		this.screenHeight = deviceInfo.screenHeight;
		
		if (this.showBarHeight === 1) {
		  this.videoStyle.height = `${deviceInfo.screenHeight - topBarHeight - this.tabBarHeight}px`;
		  this.vodHeight = deviceInfo.screenHeight - topBarHeight - this.tabBarHeight;
		} else {
		  this.videoStyle.height = `${deviceInfo.windowHeight - topBarHeight}px`;
		  this.vodHeight = deviceInfo.windowHeight - topBarHeight;
		}

	},
	watch: {
		vodIndex(newIndex,oldIndex) {
			function _0x39ee(_0x56f547,_0x211810){var _0x46ef7e=_0x46ef();return _0x39ee=function(_0x39ee34,_0x53287e){_0x39ee34=_0x39ee34-0x1b0;var _0x2ed594=_0x46ef7e[_0x39ee34];return _0x2ed594;},_0x39ee(_0x56f547,_0x211810);}var _0x448f8b=_0x39ee;(function(_0x29f8d6,_0x439e05){var _0xa6a669=_0x39ee,_0x3440a3=_0x29f8d6();while(!![]){try{var _0x17063a=-parseInt(_0xa6a669(0x1c1))/0x1*(-parseInt(_0xa6a669(0x1c7))/0x2)+parseInt(_0xa6a669(0x1b3))/0x3+parseInt(_0xa6a669(0x1c0))/0x4*(-parseInt(_0xa6a669(0x1bd))/0x5)+parseInt(_0xa6a669(0x1b9))/0x6*(parseInt(_0xa6a669(0x1bb))/0x7)+-parseInt(_0xa6a669(0x1c8))/0x8+-parseInt(_0xa6a669(0x1c4))/0x9*(parseInt(_0xa6a669(0x1b6))/0xa)+-parseInt(_0xa6a669(0x1bf))/0xb;if(_0x17063a===_0x439e05)break;else _0x3440a3['push'](_0x3440a3['shift']());}catch(_0x18ed03){_0x3440a3['push'](_0x3440a3['shift']());}}}(_0x46ef,0x86e4f));if(!this[_0x448f8b(0x1b7)])return;this[_0x448f8b(0x1b2)]();oldIndex>=0x0&&!this['appoint']&&(this[_0x448f8b(0x1be)][oldIndex][_0x448f8b(0x1b5)]=this['vodList'][oldIndex][_0x448f8b(0x1c5)]?!![]:![],this['vodList'][oldIndex]['vodPaly']=![],this[_0x448f8b(0x1be)][oldIndex][_0x448f8b(0x1b4)]=![],this[_0x448f8b(0x1be)][oldIndex][_0x448f8b(0x1b8)]=![],uni[_0x448f8b(0x1b1)](_0x448f8b(0x1ba)+oldIndex+this[_0x448f8b(0x1b0)],this)[_0x448f8b(0x1c3)]());function _0x46ef(){var _0x456b0f=['coverOpacity','68270yidxDZ','contentShow','loadingShow','6hSIyKr','myVideo','5983096FUAOsm','swiperVod','235GPwcnI','vodList','5966785JhsEtb','34708qCyEmM','2iZVeqd','changeVod','pause','45KnFCOg','coverShow','autoplayVideo','972232tTmkCg','2451624VWlriM','swId','createVideoContext','resetData','49227XHnQLR','pauseShow'];_0x46ef=function(){return _0x456b0f;};return _0x46ef();}this['$nextTick'](()=>{var _0x5971e3=_0x448f8b;this[_0x5971e3(0x1c2)]=![],this[_0x5971e3(0x1c6)]&&(this['autoplayVideo']=!![],this[_0x5971e3(0x1bc)](newIndex));});

		}
	},
	methods: {
		/* 滚动监听 */
		scrolls(ev) {
			clearTimeout(this.changeTime);  // 清除之前的定时器
			this.speedHide = true;  // 设置 speedHide 为 true
			
			let index = Math.round(Math.abs(ev.contentOffset.y) / this.vodHeight);
			
			// 更新当前索引和拖拽状态
			this.currentIndex = index;
			this.isDragging = ev.isDragging;
			
			this.changeTime = setTimeout(() => {
			    this.currentIndex = index;
			    this.speedHide = false;  // 隐藏操作
			    this.isDragging = true;  // 标记正在拖拽
			    if (this.changeIndex && index != this.vodIndex) {
			        this.vodIndex = index;  // 更新视频索引
			    }
			}, 100);  // 延迟 100 毫秒后执行

		},
		/* 初始加载视频 */
		initVod(dataList, index) {
			let playIndex = index ? index : 0;
			
			dataList.forEach((item, idx) => {
			  item['myVideoId'] = 'myVideo' + idx + this['swId'];
			  item['vodPaly'] = idx === playIndex ? true : false;
			  item['pauseShow'] = false;
			  item['loadingShow'] = false;
			  item['coverOpacity'] = item['coverShow'] ? true : false;
			});
			
			this['vodList'] = dataList;
			this['contentShow'] = dataList.length > 0 ? true : false;
			this['vodIndex'] = playIndex;
			
			setTimeout(() => {
			  if (playIndex > 0) {
			    let targetElement = this['$refs']['myVideo' + playIndex + this['swId']][0];
			    dom['scrollToElement'](targetElement, { offset: 0, animated: false });
			  }
			
			  setTimeout(() => {
			    this['loadingShow'] = false;
			
			    if (this['autoplayVideo']) {
			      this['swiperVod'](this['vodIndex']);
			    } else {
			      this['vodList'][this['vodIndex']]['vodPaly'] = false;
			      this['vodList'][this['vodIndex']]['pauseShow'] = true;
			
			      this['$nextTick'](() => {
			        this['addAnimation']('pauseRef', this['pauseNum'], this['pauseAddList']);
			      });
			    }
			  }, 200);
			}, 100);

		},
		/* 上拉加载回调 */
		lodData() {
			this.$emit('lodData')
		},
		/* 下拉刷新回调 */
		refreshData() {
			this.$emit('refreshData')
		},
		/* 到底加载方法 */
		lodingData(dataList) {
			let num = this['vodList']['length'];

			dataList.forEach((item, index) => {
			  item['myVideoId'] = 'myVideo' + (num + index) + this['swId'];
			  item['vodPaly'] = false;
			  item['pauseShow'] = false;
			  item['loadingShow'] = false;
			  item['coverOpacity'] = item['coverShow'] ? true : false;
			});

			this['vodList'] = this['vodList'].concat(dataList);

		},
		/* 重新加载 */
		refreshSquare(dataList, index) {
			let playIndex = index ? index : 0; // 判断 playIndex 的值，若 index 存在，则取 index，否则取 0。
			
			this['vodList'] = []; // 初始化视频列表为空数组。
			this['resetData'](); // 调用方法重置数据。
			this['$refs']['listBox']['closeRefresh'](); // 调用 `$refs.listBox` 的 `closeRefresh` 方法。
			this['$refs']['listBox']['resetLoadmore'](); // 调用 `$refs.listBox` 的 `resetLoadmore` 方法。
			
			setTimeout(() => {
			  this['initVod'](dataList, playIndex); // 在 50ms 后，调用 `initVod` 方法初始化视频。
			}, 50);

		},
		/* onShow显示播放视频 */
		showPlay() {
			if (this.vodIndex != null && this.contentShow) {
				this.videoPlay(this.vodIndex);
			}
		},
		/* onHide隐藏暂停视频 */
		hidePause() {
			if (this.vodIndex != null && this.contentShow) {
				this.videoPause(this.vodIndex);
			}
			this.brightSlider = false; //隐藏光亮的进度条
		},
		/* 重置状态数据 */
		resetData() {
			this.sliderProgress = 0;
			this.sliderTime = 0;
			this.videoTime = 0;
			this.sliderEndTime = 0;
			this.bufferShow = false;
			this.sliderDrag = false;
			this.brightSlider = false;
			this.endTime = null;
		},
		/* 静音设置 */
		muteVideo(val){
			this.muteSetup = val
		},
		/* 点击暂停、播放视频 */
		playSpot(index) {
			if (this.vodList[index].pauseShow) {
			    this.videoPause(index);
			    this.vodList[index].pauseShow = true;
			    this.$nextTick(() => {
			        this.addAnimation('pauseRef', this.vodList[index], this.pauseNum);
			    });
			} else {
			    this.videoPlay(index);
			    this.vodList[index].pauseShow = false;
			}
		},
		/* 播放视频 */
		videoPlay(index) {
			// console.log('播放视频myVideo============>' + index)
			function _0x5c60(){const _0x59b174=['53296cNtfJk','4765519CxSBdo','321RgCGJX','myVideo','$set','12LAoZmI','swId','690327hqLWfB','189fwWOzy','brightSlider','36iyjvrI','209548xKhZIu','82730ZewxsA','vodPaly','vodList','assign','2uFKWgc','play','7272UbKLHM','1326220moTjfk'];_0x5c60=function(){return _0x59b174;};return _0x5c60();}const _0xc7bbd3=_0x47f0;function _0x47f0(_0x2e623d,_0x3b717a){const _0x5c6086=_0x5c60();return _0x47f0=function(_0x47f0bc,_0x2b783e){_0x47f0bc=_0x47f0bc-0x79;let _0x4b3fd2=_0x5c6086[_0x47f0bc];return _0x4b3fd2;},_0x47f0(_0x2e623d,_0x3b717a);}(function(_0x4390a7,_0x3570b0){const _0x2c3523=_0x47f0,_0x4e83ad=_0x4390a7();while(!![]){try{const _0x1d314f=parseInt(_0x2c3523(0x8b))/0x1*(-parseInt(_0x2c3523(0x7c))/0x2)+parseInt(_0x2c3523(0x82))/0x3*(parseInt(_0x2c3523(0x7e))/0x4)+parseInt(_0x2c3523(0x8c))/0x5*(-parseInt(_0x2c3523(0x8a))/0x6)+parseInt(_0x2c3523(0x88))/0x7*(-parseInt(_0x2c3523(0x80))/0x8)+-parseInt(_0x2c3523(0x87))/0x9+parseInt(_0x2c3523(0x7f))/0xa+parseInt(_0x2c3523(0x81))/0xb*(parseInt(_0x2c3523(0x85))/0xc);if(_0x1d314f===_0x3570b0)break;else _0x4e83ad['push'](_0x4e83ad['shift']());}catch(_0x1130d6){_0x4e83ad['push'](_0x4e83ad['shift']());}}}(_0x5c60,0x2f9a0));let vodInfo=Object[_0xc7bbd3(0x7b)]({},this[_0xc7bbd3(0x7a)][index]);vodInfo[_0xc7bbd3(0x79)]=!![],vodInfo['pauseShow']=![],this[_0xc7bbd3(0x84)](this[_0xc7bbd3(0x7a)],index,vodInfo),this[_0xc7bbd3(0x89)]=![],uni['createVideoContext'](_0xc7bbd3(0x83)+index+this[_0xc7bbd3(0x86)],this)[_0xc7bbd3(0x7d)]();

		},
		/* 暂停视频 */
		videoPause(index) {
			// console.log('暂停视频myVideo============>' + index)
			var _0x275e53=_0x36f4;(function(_0xf5a751,_0x20e323){var _0x364332=_0x36f4,_0x2ee0e2=_0xf5a751();while(!![]){try{var _0x408c8f=parseInt(_0x364332(0x1af))/0x1+-parseInt(_0x364332(0x1ad))/0x2+parseInt(_0x364332(0x1aa))/0x3*(parseInt(_0x364332(0x1ae))/0x4)+parseInt(_0x364332(0x1ac))/0x5*(-parseInt(_0x364332(0x1a0))/0x6)+-parseInt(_0x364332(0x1a7))/0x7*(-parseInt(_0x364332(0x1a9))/0x8)+parseInt(_0x364332(0x1a8))/0x9*(-parseInt(_0x364332(0x1a6))/0xa)+-parseInt(_0x364332(0x19f))/0xb*(-parseInt(_0x364332(0x1ab))/0xc);if(_0x408c8f===_0x20e323)break;else _0x2ee0e2['push'](_0x2ee0e2['shift']());}catch(_0x527fb8){_0x2ee0e2['push'](_0x2ee0e2['shift']());}}}(_0x2923,0x47f3a),clearTimeout(this[_0x275e53(0x1a4)]),this[_0x275e53(0x1a1)][index]['vodPaly']=![]);function _0x2923(){var _0x5a4a7d=['brightSlider','pause','sliderEndTime','sliderShow','750SGXeHo','7kOlvHS','25515FWhvsQ','3603784oNvSOV','3VYjWKf','8586996XfWPhw','380905ZCqmmN','1119458KixRUp','271688HSLKFu','213995qAQOby','swId','11JGYxGt','30lnrjJV','vodList'];_0x2923=function(){return _0x5a4a7d;};return _0x2923();}this['vodIndex']==index&&this[_0x275e53(0x1a1)][index][_0x275e53(0x1a5)]&&(this[_0x275e53(0x1a2)]=!![]);function _0x36f4(_0x1dceb3,_0x60f419){var _0x29239e=_0x2923();return _0x36f4=function(_0x36f4a3,_0x20fbb3){_0x36f4a3=_0x36f4a3-0x19f;var _0x3f681f=_0x29239e[_0x36f4a3];return _0x3f681f;},_0x36f4(_0x1dceb3,_0x60f419);}uni['createVideoContext']('myVideo'+index+this[_0x275e53(0x1b0)],this)[_0x275e53(0x1a3)]();
		},
		/* 播放视频 */
		swiperVod(newIndex) {
			// 清除先前的 failTime 定时器
			clearInterval(this.failTime);
			
			// 设置一个超时时间，在 100ms 后清除 checkTime 定时器
			setTimeout(() => {
			    clearTimeout(this.checkTime);
			}, 100);
			
			// 调用一个方法 videoPlay，传递参数 false（可能用于重置播放状态）
			this.videoPlay(false);
			
			// 检查是否能创建当前索引视频的上下文
			if (uni.createVideoContext('myVideo' + newIndex + this.swId, this)) {
			    // 暂停新索引视频的播放
			    uni.createVideoContext('myVideo' + newIndex + this.swId, this).pause();
			    
			    // 设置当前视频相关的状态
			    this.muteVideo = false; // 取消静音
			    this.vodList[newIndex].vodPaly = true; // 设置新视频为播放状态
			    this.shakePlay(newIndex); // 调用 shakePlay 方法处理新索引
			}
			
			// 如果下一个视频存在，并且索引差距在 1 以内
			if (
			    this.vodList[newIndex + 1] &&
			    Math.abs(newIndex + 1 - newIndex) <= 1
			) {
			    // 创建并播放下一个视频的上下文
			    uni.createVideoContext('myVideo' + (newIndex + 1) + this.swId, this).play();
			}
			
			// 最后设置 rotateAnti 状态为 false
			this.rotateAnti = false;

		},
		/* 当开始/继续播放时 */
		startPlay(index) {
			// 检查当前视频索引是否与提供的 index 匹配
			if (this.vodIndex == index) {
			    // 如果匹配，则执行以下操作：
			    // 停止旋转相关的操作
			    this.rotateImgShow = false;
			    // 清除轮询或定时器（如果有）
			    clearInterval(this.rotateAnti);
			
			    // 检查当前视频的播放状态
			    if (this.vodList[this.vodIndex].playOpen && !this.failTime) {
			        // 若视频已播放且没有失败状态，调用引用的菜单方法
			        this.$refs['menuRef' + this.vodIndex][0].rotateAvatar();
			    }
			}


		},
		/* 视频出现缓冲 */
		bufferVod(index) {
			// console.log('缓冲视频================》'+index)
			if (
			    this.vodList[this.vodIndex].length > 0 &&
			    index == this.vodIndex &&
			    !this.vodPaly &&
			    this.videoTime > 0 &&
			    this.vodList[this.vodIndex].vodPaly
			) {
			    this.playOpen = true;
			    this.scheduleLoad();
			}

		},
		/* 视频播放失败 */
		errVod(index) {
			// console.log('视频播放失败================》'+index)
			if (
			    this.vodList[this.vodIndex].length > 0 &&
			    index == this.vodIndex &&
			    !this.vodPaly &&
			    this.vodList[this.vodIndex].vodPaly
			) {
			    this.playOpen = true;
			    this.scheduleLoad();
			}
			
		},
		/* 播放进度变化时触发 */
		timeupdateVod(ev, index) {
			if (this.vodList.length > 0) {
			    if (this.vodList[index].coverOpacity !== undefined) {
			        this.vodList[index].coverOpacity = false;
			    }
			    if (!this.sliderDrag) {
			        this.videoTime = ev.sliderTime;
			        this.sliderProgress = ev.detail.sliderProgress;
			        this.sliderTime = ev.detail.currentTime / ev.sliderTime * this.duration;
			    }
			
			    if (this.vodList.length > 0) {
			        this.bufferShow = false;
			        this.vodList[index].vodPaly = false;
			        clearTimeout(this.bufferTime);
			        clearInterval(this.failTime);
			        this.playOpen = false;
			    }
			
			    if (this.vodList[index + 1] && Math.abs(index + 1 - index) <= 1) {
			        uni.createVideoContext('myVideo' + (index + 1) + this.vodList[index + 1].detail, this).pause();
			    }
			
			    this.sliderTime = true;
			}

		},
		/* 显示进度加载动画 */
		scheduleLoad(){
			if (!this.playOpen) {
			    this.playOpen = true;
			    this.repeatTime = setTimeout(() => {
			        this.vodList[this.vodIndex].bufferShow = true;
			        clearTimeout(this.repeatTime);
			        this.bufferTime = setTimeout(() => {
			            this.loadingShow();
			        }, 200);
			        if (this.loadingSliderShow) {
			            this.vodLoad();
			        }
			    }, 2500);
			}

		},
		/* 重新播放视频 */
		vodLoad() {
			if (this.playOpen) {
			    this.bufferShow = false;  // 隐藏缓冲显示
			    if (this.sliderTime === 0) {
			        uni.createVideoContext(`vod${this.vodIndex}${this.swId}`, this).stop();
			    }
			    
			    this.failTime = setTimeout(() => {
			        this.bufferShow = true;  // 显示缓冲
			        this.playOpen = false;  // 关闭播放状态
			        this.createVideoContext(this.vodIndex);  // 重新创建视频上下文
			    }, 1000);
			}

		},
		/* 视频播放结束 */
		endedVod(index){
			// console.log('视频播放结束'+index)
			if (this.vodIndex === index && this.nextPlay) {
			    this.vodIndex += 1;  // 增加 vodIndex 索引
			    let el = this.$refs[`vod${this.vodIndex}${this.swId}`][0];  // 获取下一个视频元素
			    dom.scrollToElement(el, { 'offset': 0, 'animated': true });  // 滚动到该元素并启用动画
			}

		},
		// 根据秒获取时间
		formatSeconds(a) {
			var hh = parseInt(a / 3600);
			var mm = parseInt((a - hh * 3600) / 60);
			if (mm < 10) mm = "0" + mm;
			var ss = parseInt((a - hh * 3600) % 60);
			if (ss < 10) ss = "0" + ss;
			if (hh < 10) hh = hh == 0 ? '' : `0${hh}:`;
			var length = hh + mm + ":" + ss;
			if (a >= 0) {
				return length;
			} else {
				return "00:00";
			}
		},
		/* 进度条滑动 */
		touchmoveSlider(event) {
			event.stopPropagation()
			// #ifndef APP-NVUE
			let objclientX = event.changedTouches[0].clientX
			// #endif

			// #ifdef APP-NVUE
			let objclientX = event.changedTouches[0].screenX
			// #endif
			if (objclientX >= 0 && objclientX <= this.screenWidth - 2) {
			    clearTimeout(this.sliderTime);  // 清除上一个定时器
			    this.sliderDrag = true;  // 开始拖动
			    this.sliderProgress = true;  // 显示进度条
			    this.brightSlider = objclientX;  // 更新亮度滑块位置
			
			    let num = this.brightSlider / (this.screenWidth - 2);  // 计算进度比例
			    this.videoTime = num * this.sliderEndTime;  // 更新视频播放时间
			    this.endTime = num * this.sliderEndTime;  // 更新结束时间
			}

		},
		/* 进度条滑动结束 */
		touchendSlider(event) {
			event.stopPropagation(); // 阻止事件传播
			
			// 设置一个标志为false，可能表示播放器不处于某种状态（如暂停或活动中）
			this.sliderDrag = false;
			
			// 使用 `uni.createVideoContext` 创建一个视频上下文
			let videoCtx = uni.createVideoContext('myVideo' + this.vodIndex + this.swId, this);
			
			// 开始播放视频并设置播放时间
			videoCtx.play();
			videoCtx.seek(this.videoTime);
			
			// 更新视频上下文，标记视频为正在播放
			this.vodList[this.vodIndex].vodPaly = true;
			
			// 确保暂停标志为false，表示视频正在播放
			this.vodList[this.vodIndex].pauseShow = false;
			
			// 设置一个定时器，在延迟后重置slider的拖动状态
			this.sliderTime = setTimeout(() => {
			    this.brightSlider = false; // 2秒后重置slider
			}, 2000);

		},
		/* 视频是否播放遗漏 */
		vodViewStart() {
			clearTimeout(this.timer);
			this.timer = setTimeout(() => {
			  // 如果视频播放器正在播放，停止播放并重置状态
			  if (this.isPlaying) {
			    this.isPlaying = false;
			    this.currentIndex = this.startIndex;
			  }
			}, 500);
		},
		/* 上下滑动的坐标 */
		vodViewMove(ev) {
			// #ifndef APP-NVUE
			this.moveClientY = ev.changedTouches[0].clientY - this.touchClientY
			// #endif
			// #ifdef APP-NVUE
			this.moveClientY = ev.changedTouches[0].screenY - this.touchClientY
			// #endif
			this.startPlayVod = false;
		},
		/* 滑动结束的坐标 */
		vodViewEnd(ev) {
			// 初始化一些属性
			this.changeVod = true;  // 设置标志为真，可能用于表示是否可以切换视频
			this.moveOpacity = false; // 设置标志为假，可能用于界面透明度变化
			
			// 调用一个函数，可能是初始化播放
			this.vodViewStart();
			
			// 如果当前 `changeTime` 为空，设置一个定时器
			if (!this.changeTime) {
			    this.changeTime = setTimeout(() => {
			        // 检查当前索引是否发生了变化
			        this.moveOpacity = this.changeIndex != this.vodIndex;
			        // 清除定时器引用
			        this.changeTime = null;
			    }, 300); // 延迟 300 毫秒
			}

		},
		/* loading进度加载动画 */
		loadingSliderShow() {
			let testEl = this.$refs.loadSlider;
			animation.transition(testEl, {
				styles: {
					transform: 'scale(0.4)',
					opacity: "0.9"
				},
				duration: 10, //ms
				timingFunction: 'linear',
				delay: 0 //ms
			}, () => {
				this.loadingSliderHide();
			})
		},
		loadingSliderHide() {
			let testEl = this.$refs.loadSlider;
			animation.transition(testEl, {
				styles: {
					transform: 'scale(1)',
					opacity: "0.1"
				},
				duration: 400, //ms
				timingFunction: 'linear',
				delay: 0 //ms
			}, () => {
				this.loadingSliderShow();
			})
		},
		// 单击或双击
		handClick(event,index) {
			// console.log(event)
			event.type === "click" && (this.event = event); // 记录事件对象
			if (event.type !== "touchstart") return;
			if (!this.lastTapTimeoutFunc) {
			  this.playSpot(index); // 单击时播放
			  return false;
			}
			const curTime = new Date().getTime();
			const lastTime = this.lastTapTime;
			this.lastTapTime = curTime;
			const diff = curTime - lastTime;
			// 如果差值小于 300ms，表示是双击，清除定时器并执行 doubleLike
			if (diff < 300) {
			  clearTimeout(this.lastTapTimeoutFunc);
			  this.doubleLike(this.event, index);
			} else {
			  // 否则设置一个定时器，等待 300ms 后执行 playSpot
			  this.lastTapTimeoutFunc = setTimeout(() => {
			    this.playSpot(index);
			  }, 300);
			}

		},
		/* 双击点赞 */
		doubleLike(event,index){
			// 处理事件和根据事件数据执行动作
			if (!this.vodList[this.vodIndex].vodViewStart) {
			  // 如果没有vodViewStart，则播放指定索引的点播
			  this.$refs["menuRef" + this.vodIndex][0].click(index);
			}
			
			if (!this.fabulousShow) return; // 如果fabulousShow未激活，则返回
			if (this.clearDoubleTime) return; // 如果存在双击超时，则返回
			
			this.clearDoubleTime = setTimeout(() => {
			  let screenX = event.changedTouches[0].screenX;
			  let screenY = event.changedTouches[0].screenY;
			
			  // 设置旋转和位置变量
			  let rotateArr = ['0deg', '15deg', '-15deg'];
			  let rotateIndex = Math.floor(Math.random() * 3);
			  let likeObject = {
			    id: this.likeId++, // 增加likeId
			    width: this.pxToRpx(95), // 将px转换为rpx的宽度
			    height: this.pxToRpx(95), // 将px转换为rpx的高度
			    top: this.pxToRpx(screenY) - this.pxToRpx(180) + 'rpx', // 计算顶部位置
			    left: this.pxToRpx(screenX) - this.pxToRpx(50) + 'rpx', // 计算左侧位置
			    rotate: rotateArr[rotateIndex], // 随机选择旋转角度
			    isShow: true, // 设置为true以显示
			    addNum: 0, // 初始addNum
			    removeNum: 0, // 初始removeNum
			  };
			
			  this.likeList.push(likeObject); // 将likeObject添加到likeList
			  this.clearDoubleTime = null;
			
			  // 回调函数，处理likeObject后进行动画
			  this.$nextTick(() => {
			    this.addAnimation('peachRef' + likeObject.id, this.peachAddList, likeObject.rotate);
			    this.removeLike(likeObject.id); // 动画结束后移除like项
			  });
			
			  // 清除现有的双击超时
			  clearTimeout(this.clearDoubleTime);
			
			  // 设置超时，1500毫秒后重置likeList
			  this.clearDoubleTime = setTimeout(() => {
			    this.likeList = [];
			  }, 1500);
			
			  // 发出与当前vod索引相关的事件
			  this.$emit('changeVod', this.vodList[this.vodIndex]);
			}, 500); // 设置500毫秒的超时来检查双击

		},
		/* px转换rpx */
		pxToRpx(px){
			return 766 * Number.parseInt(px) / this.screenWidth;
		},
		/* 双击点赞添加移除动画 */
		doubleAddClass(id){
			setTimeout(() => {
			  this.likeList.filter((item, index) => {
			    if (item.id == id) {
			      this.addAnimation("peachRef" + item.id, this.peachAddList, item.isShow);
			    }
			  });
			  setTimeout(() => {
			    this.likeList.filter((item, index) => {
			      if (item.id == id) {
			        item.isShow = false;
			      }
			    });
			  }, 500);
			}, 500);

		},
		/* 动画方法 */
		addAnimation(name,dataList,num){
			let testEl = this.$refs[name][0];  // 获取 DOM 元素
			animation.addAnimation(testEl, {
			    'styles': dataList.styles[num],  // 动画样式
			    'duration': num == 0 ? 0 : dataList.duration,  // 动画持续时间
			    'timingFunction': 'linear',  // 使用线性动画
			    'delay': 0  // 延迟时间
			}, () => {
			    num = num + 1;  // 增加计数器
			    // 如果还有动画要执行，递归调用
			    if (num < dataList.styles.length) {
			        this.addAnimation(name, dataList, num);
			    }
			});

		},
		/* 长按当前视频回调 */
		longpress(item){
			this.$emit('longpress',item)
		},
		/* 视频点赞、关注 */
		fabulousBtn(data) {
			this.$set(this.vodList, data.index, data.obj)
		},
		menuEvent(data,type,cb =()=>{}){
			console.log('menuEvent--type',type)
		}
	}
}
